package com.leo.datastruct.sort;

/**
 *
 * @author xuexiaolei
 * @version 2018年02月02日
 */
public class StraightInsertionSort extends Sortable {

    public StraightInsertionSort(String sortMethodName) {
        super(sortMethodName);
    }

    @Override
    public void sort(int[] s) {
        for (int i = 1; i < s.length; i++) {
            int temp = s[i];
            int j = i;
            while (j>0 && s[j-1] > temp){
                s[j] = s[j-1];
                j--;
            }
            s[j] = temp;
        }
    }

    public static void main(String[] args) {
        Sortable a = new StraightInsertionSort("直接插入排序");
        a.testSort(new int[]{49,38,65,97,76,13,27,49,78,34,12,64,1});
    }
}
